<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:ui="http://java.sun.com/jsf/facelets" 
	xmlns:f="http://java.sun.com/jsf/core" 
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j" 
	xmlns:rich="http://richfaces.org/rich" template="/template.xhtml">
	<ui:define name="pageTitle">
		<h:outputText styleClass="outputText" id="textPageTitle" value="Check-up Survey" />
	</ui:define>
	<ui:define name="pageContent">
		<f:loadBundle var="msg" basename="messages"/>
		<h:form styleClass="form" id="form1">
		<ui:include src="/common/message.xhtml"/>
		<rich:panel id="panelSearch">
		<table width="70%" align="center" style="border: 1px solid #777777">
			<tr>
				<td height="30px" colspan="3" style="padding-top: 19px; padding-left: 40px">
					<h:outputLabel value="HN# : "/>
					<h:inputText id="hn" value="#{searchBean.hn}" required="true"/>
					<rich:message for="hn" ajaxRendered="true"/>
				</td>
			</tr>
			<tr>
				<td colspan="3" height="60px" align="center" style="padding-left: 40px">
					<h:commandButton type="submit" value="ค้นหาประวัติ" styleClass="btn-command" action="#{searchBean.search}" />
					<h:outputLabel value="     " styleClass="outputLabel" />
					<h:commandButton type="submit" value="กรอกข้อมูลใหม่" styleClass="btn-command" disabled="true" rendered="#{empty searchBean.patient.hnFlag}"/>
					<h:commandButton type="submit" value="กรอกข้อมูลใหม่" styleClass="btn-command" action="#{packageBean.prepareCreate}" rendered="#{not empty searchBean.patient.hnFlag}">
						<f:setPropertyActionListener target="#{packageBean.hn}" value="#{searchBean.patient.hn}" />
						<f:setPropertyActionListener target="#{packageBean.hnFlag}" value="#{searchBean.patient.hnFlag}" />
						<f:setPropertyActionListener target="#{packageBean.checkupFlag}" value="#{searchBean.patient.checkupFlag}" />
						<f:setPropertyActionListener target="#{packageBean.contactId}" value="#{searchBean.patient.contactId}" />
					</h:commandButton>
				</td>
			</tr>
		</table>
		<br/>
		<br/>
		<table id="tblResult" width="70%" align="center" cellpadding="2" cellspacing="0">
			<tr>
				<td align="center">
					<font size="3">
					<h:outputLabel value="HN# : "/>
					<h:outputLabel value="#{searchBean.patient.hn}"/>
					<h:outputLabel value="  "/>
					<h:outputLabel value="#{searchBean.patient.title}"/><h:outputLabel value="  "/>
					<h:outputLabel value="#{searchBean.patient.name}"/><h:outputLabel value="  "/>
					<h:outputLabel value="#{searchBean.patient.surname}"/>

					<!-- h:outputLabel value="[HN Flag:"/><h:outputLabel value="#{searchBean.patient.hnFlag}"/><h:outputLabel value="]"/ -->
					<!-- h:outputLabel value="[Checkup Flag:"/><h:outputLabel value="#{searchBean.patient.checkupFlag}"/><h:outputLabel value="]"/ -->
					</font>
				</td>
			</tr>
			<tr>
				<td>	
				<rich:dataTable border="1" cellpadding="0" cellspacing="0" 
					columnClasses="columnClassCenter, columnClassCenter, columnClassLeft, columnClassRight, columnClassCenter, columnClassCenter" 
					headerClass="headerClass" footerClass="footerClass" rowClasses="rowClass1, rowClass2" styleClass="dataTable"
					id="table" style="width:100%" value="#{searchBean.items}" var="varitems" rows="10">
					<rich:column>
						<f:facet name="header">
							<h:outputText value="เรียกดู"/>
						</f:facet>
						<h:commandButton type="button" image="#{resource['images:edit.png']}" action="#{packageBean.prepareEdit}">
							<f:setPropertyActionListener target="#{packageBean.id}" value="#{varitems.id}" />
							<f:setPropertyActionListener target="#{packageBean.contactId}" value="#{searchBean.patient.contactId}" />
						</h:commandButton>
					</rich:column>
					<rich:column>
						<f:facet name="header">
							<h:outputText value="Visit Date" />
						</f:facet>
						<h:outputText value="#{varitems.visitDateStr}"/>
					</rich:column>
					<rich:column>
						<f:facet name="header">
							<h:outputText value="Checkup Package" />
						</f:facet>
						<h:outputText value="#{varitems.packageName}"/>
					</rich:column>
					<rich:column>
						<f:facet name="header">
							<h:outputText value="Amount" />
						</f:facet>
						<h:outputText value="#{varitems.amount}">
							<f:convertNumber pattern="###,###,##0.00"/>					
						</h:outputText>
					</rich:column>
					<rich:column>
						<f:facet name="header">
							<h:outputText value="Status" />
						</f:facet>
						<h:outputText styleClass="outputText" value="#{varitems.status}"/>
					</rich:column>
					<rich:column>
						<f:facet name="header">
							<h:outputText value="ประวัติสุขภาพ"/>
						</f:facet>
						<h:outputLink target="_blank" value="#{msg['page.view.history']}">
							<f:param name="i_answerId" value="#{varitems.id}" />
							<h:outputText value="Link" />
						</h:outputLink>						
					</rich:column>
					<f:facet name="footer">
						<h:panelGroup>
							<h:panelGroup rendered="#{!empty searchBean.items}">
	                			<rich:dataScroller align="center" page="#{searchBean.page}" />
	                		</h:panelGroup>
	                		<h:panelGroup rendered="#{empty searchBean.items}">
	                			<h:outputText value="No Data."></h:outputText>
	                		</h:panelGroup>
	                	</h:panelGroup>
	            	</f:facet>
				</rich:dataTable>		
				</td>
			</tr>	
		</table>
		</rich:panel>
		</h:form>
	</ui:define>
</ui:composition>